<?php

namespace App\Http\Resources\Kms\Attendance;

use App\Http\Resources\BaseResource;
use App\Models\Kms\Attendance\AttendanceDailyPointTraceModel;
use Illuminate\Http\Request;

class FieldListDetailResource extends BaseResource
{
    /**
     * @param Request $request
     * @return array
     */
    public function toArray($request)
    {
        $extra = empty($this->extra) ? [] : json_decode($this->extra, true);
        return [
            "id"                    => $this->id,
            "tracePointFullTime"    => date("Y-m-d H:i:s", $this->tracePointTime),
            "tracePointTime"        => date("H:i", $this->tracePointTime),
            "dailyGatherId"         => $this->dailyGatherId,
            "gpsSwitch"             => $this->gpsSwitch,
            "wifiSwitch"            => $this->wifiSwitch,
            "cellularNetworkSwitch" => $this->cellularNetworkSwitch,
            "dumpEnergy"            => $this->dumpEnergy,
            "longitude"             => $this->longitude,
            "latitude"              => $this->latitude,
            "lastPointDistance"     => $this->lastPointDistance,
            "status"                => $this->status,
            "statusText"            => AttendanceDailyPointTraceModel::STATUS_TEXT[$this->status] ?? "",
            "address"               => $this->address,
            "deviceModel"           => $this->deviceModel,
            "deviceSystem"          => $this->deviceSystem,
            "deviceSerialNumber"    => $this->deviceSerialNumber,
            "extra"                 => $extra,
            "locationType"          => attributeGet($extra, "locationType", null),
            "locationTypeText"      => translateEnumCodeToCn(
                AttendanceDailyPointTraceModel::LOCATION_TYPE_TEXT,
                attributeGet($extra, "locationType", null),
                "-"
            ),
            "accuracy"              => attributeGet($extra, "accuracy", null)
        ]; // TODO: Change the autogenerated stub
    }
}
